package treqs.servlet;

import java.io.IOException;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import treqs.model.HibernateUtil;
import treqs.model.Requirementpriority;
import treqs.model.Requirementstatus;

/**
 * Servlet implementation class RequirementStatusCreateServlet
 */
public class RequirementStatusCreateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RequirementStatusCreateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try
		{			
			response.getWriter().write("Starting<br>");
	
			EntityManagerFactory emf = HibernateUtil.getEntityManagerFactory();
			// First unit of work
			EntityManager em = emf.createEntityManager();
			EntityTransaction tx = em.getTransaction();
			tx.begin();
						
			Requirementstatus requirementStatus = new Requirementstatus();
			requirementStatus.setValue(request.getParameter("value"));
			
			em.persist(requirementStatus);
			tx.commit();
			em.close();
	
			response.getWriter().write("Done!<br>");
			return;
		}
		catch (Exception ex)
		{
			response.getWriter().write("No Luck!<br>");
			response.getWriter().write(ex.toString());
			return;
			
		}

	}

}
